package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.login.EnableLoginAuth;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.user.UserInfo;
import com.atguigu.tingshu.model.user.UserPaidAlbum;
import com.atguigu.tingshu.model.user.UserPaidTrack;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.user.service.UserPaidAlbumService;
import com.atguigu.tingshu.user.service.UserPaidTrackService;
import com.atguigu.tingshu.vo.user.UserInfoVo;
import com.google.j2objc.annotations.AutoreleasePool;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "用户管理接口")
@RestController
@RequestMapping("api/user/userInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserInfoApiController {

    @Autowired
    private UserInfoService userInfoService;

    @Autowired
    private UserPaidTrackService userPaidTrackService;

    @Autowired
    private UserPaidAlbumService userPaidAlbumService;

    @GetMapping("/findUserById/{userId}")
    public Result<UserInfo> findUserById(@PathVariable Long userId) throws InterruptedException {
        Thread.sleep(50);
        UserInfo userInfo = userInfoService.getById(userId);
        return Result.ok(userInfo);
    }

    @EnableLoginAuth
    @GetMapping("/findPayAlbum/{albumId}")
    public Result<Boolean> findPayAlbum(@PathVariable Long albumId) {
        Boolean flag = userPaidAlbumService.findPayAlbum(albumId);
        return Result.ok(flag);
    }

    @EnableLoginAuth
    @GetMapping("/findPayTrack/{albumId}")
    public Result<List<UserPaidTrack>> findPayTrack(@PathVariable Long albumId) {
        List<UserPaidTrack> userPaidTrack = userPaidTrackService.findPayTrack(albumId);
        return Result.ok(userPaidTrack);
    }

    //修改用户vip的状态
    @PutMapping("/updateVipState")
    public Result updateVipState(){
        this.userInfoService.updateVipState();
        return Result.ok();
    }
}

